﻿@model Fcom.VNInsurance.Web.ViewModel.CompanyViewModel
@{
    ViewBag.Title = "EditCompany";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
}
<link rel="stylesheet" href="@Url.Content("~/Content/treeview/jquery.treeview.css")" />
<link href="@Url.Content("~/Content/contextmenu/jquery.contextMenu.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Content/treeview/jquery.treeview.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/contextmenu/jquery.ui.position.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/contextmenu/jquery.contextMenu.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {

        $(".fancybox-close").click(function () {
            $("#fancy").fadeOut();
        });
     


        $("#chooseLogo").click(function () {
            $("#fancy").fadeIn();
            $("#currenttiny").html("Logo");
            return false;
        });

 
        });

        jQuery.fn.center = function () {
            this.css("position", "absolute");
            this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
                                                    $(window).scrollTop()) + "px");
            this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
                                                    $(window).scrollLeft()) + "px");
            return this;
        }

        function ajaxdbSelect(sfile) {
            currentSkfile = $(sfile);
            $(".skselected").removeClass("skselected");
            if (!currentSkfile.hasClass("skselected")) {
                currentSkfile.addClass("skselected");
            }
        }
        function ajaxSelect(sfile) {
            //if ($('.mydivclass').length) {
            currentSkfile = $(sfile);
            if (currentSkfile.hasClass("skselected")) {
                currentSkfile.removeClass("skselected");
            }
            else {
                currentSkfile.addClass("skselected");
            }
        }

        function ajaxRfiles(stringpath) {
            $.getJSON("/File/ReadFiles", { folderPath: stringpath }, function (rvdata) {
                htmlcode = "";

                var currentFolder = $(".skselected-folder").attr("rel");
                $("#skFolderContent").html("<center><img src='/Content/loading.gif'></center>");
                $(rvdata).each(function () {
                    htmlcode += "<div class='skfile' onclick=\"return ajaxSelect(this)\;\" rel='" + $(this).attr("Name") + "'>";
                    htmlcode += "<div class='skfileicon'>";
                    if ($(this).attr("isImage")) {
                        htmlcode += "<img src='" + "/" + currentFolder + "/" + $(this).attr("Name") + "'   class='skfileicon-image'/>";
                    }
                    else {

                    }
                    htmlcode += "</div>";
                    htmlcode += "<div class='skfilename'><p>" + $(this).attr("Name") + "</p></div>";
                    htmlcode += "</div>";
                });
                $("#skFolderContent").html(htmlcode);
            });
        }
        function ajaxRtree(mtree) {
            $(".skselected-folder").removeClass("skselected-folder");

            $(mtree).addClass("skselected-folder");
            currentFolder = $(mtree);
            var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader'),
                multiple: false,
                allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
                params: { FolderPath: currentFolder.attr("rel") },
                multiple: true,
                acceptFiles: "image/*",
                action: '@Url.Action("Upload", "File")',
            onComplete: function (id, fileName, responseJSON) {
                if (uploader.getInProgress() > 0) {
                    return;
                }
                else {
                    $("#refresh-listfile").click();
                }
            }
        });
        var thispath = $(mtree).attr("rel");
        ajaxRfiles(thispath);
        subul = currentFolder.next();
        parentFolder = currentFolder.parent().parent().prev();

        $.getJSON("/File/ReadFolder", { folderPath: thispath }, function (rvdata) {

            subul.addClass("closed");
            subul.html(""); htmlcode = "";
            $(rvdata).each(function () {
                if (parseInt($(this).attr("hasFiles")) > 0 ? "class=closed" : "") {
                    htmlcode += "<li class=closed><span class='folder' onclick=\"return ajaxRtree(this)\;\" rel='" + currentFolder.attr("rel") + "/" + $(this).attr("Name") + "'>";
                    htmlcode += $(this).attr("Name");
                    htmlcode += "</span><ul></ul></li>";
                } else {
                    htmlcode += "<li><span class='folder'  onclick=\"return ajaxRtree(this)\;\" rel='" + currentFolder.attr("rel") + "/" + $(this).attr("Name") + "'>";
                    htmlcode += $(this).attr("Name");
                    htmlcode += "</span></li>";
                }
            });
            subul.html(htmlcode);
        });
    }
    function ajaxReadFolder(foldername) {

        return false;
    }
    $(document).ready(function (e) {
        $(function () {
            $.contextMenu({
                selector: '.skfile',
                callback: function (key, options) {
                    var currentFileName = $(this).attr("rel");
                    var currentFolder = $(".skselected-folder").attr("rel");
                    var currentFile = $(this);
                    var currentPath = currentFolder + "/" + currentFileName;
                    if (key == "edit") {
                        $("#editFile").css("display", "block");
                        $(".edNewFileName").val(currentFileName);
                        $(".edFileName").html(currentFileName);
                    }
                    else if (key == "insert") {

                        var imagepath = $("#AppUrl").html() + "/" + currentFolder + "/" + currentFileName;

                        $("#fancy").fadeOut();
                        if ($("#currenttiny").html() == "Logo") {
                            $("#Logo").val(currentFileName);
                            $("#imgshow").attr("src", imagepath);
                        }
                        else {

                            tinymce.get($("#currenttiny").html()).selection.setContent("<img src='" + imagepath + "'/>");
                        }

                    }
                    else if (key == 'delete') {
                        //do some thing to delete file.
                        filecount = $(".skselected").length;
                        var msgtext = "tập tin " + currentFileName;

                        if (filecount > 0) {
                            msgtext = filecount + " tập tin đã chọn";
                            if (confirm("Bạn có muốn xóa " + msgtext + " ?")) {
                                $(".skselected").each(function () {
                                    var currentFileSeleted = $(this);
                                    currentFileSeletedFilename = currentFileSeleted.attr("rel");
                                    pathtodelete = currentFolder + "/" + currentFileSeletedFilename;
                                    $.getJSON("/File/ajaxDeleteFile", { spath: pathtodelete }, function (rvdata) {
                                        if (rvdata.status == true) {
                                            currentFileSeleted.remove();
                                        }
                                        else {
                                            alert(rvdata.msg);
                                        }
                                    });
                                });
                            }
                        }
                        else {
                            if (confirm("Bạn có muốn xóa " + msgtext + " ?")) {
                                //do something to deletefile..

                                pathtodelete = currentFolder + "/" + currentFileName;
                                //ajaxDeleteFile
                                $.getJSON("/File/ajaxDeleteFile", { spath: pathtodelete }, function (rvdata) {
                                    if (rvdata.status == true) {
                                        currentFile.remove();
                                    }
                                    else {
                                        alert(rvdata.msg);
                                    }
                                });
                            }
                        }
                    }
                },
                items: {
                    "edit": { name: "Rename", icon: "edit", accesskey: "e" },
                    "insert": { name: "Insert", icon: "add" },
                    "delete": { name: "Delete", icon: "delete" },
                    "sep1": "---------",
                    "quit": { name: "Quit", icon: "quit" }
                }
            });
        });
        $("#editFile").center();
        $("#browser").treeview();
        $("#edSave").click(function () {
            var currentFolder = $(".skselected-folder").attr("rel");
            var path = $(".edFileName").html();
            var newfile = $(".edNewFileName").val();
            $.getJSON("/File/ajaxRenameFile", { spath: currentFolder + "/" + path, foder: currentFolder, newfilename: newfile }, function (rvdata) {
                if (rvdata.status == true) {
                    ajaxRfiles(currentFolder);
                    $("#editFile").css("display", "none");
                }
                else {
                    alert(rvdata.msg);
                }
            });
        });

        $("#can").click(function () { $("#editFile").css("display", "none"); });
        $("#refresh-listfile").click(function () {
            var currentFolder = $(".skselected-folder").attr("rel");
            ajaxRfiles(currentFolder);
            return false;
        });

    });

</script>
<style>
    input[type="text"] {
        font-size:12px;
    }
    .title {
        font-family:Tahoma;
        font-size:14px;
        color:blue;
    }
    .textbox {
        float:left;
        width:300px;
        margin-bottom:5px;
    }
    .error {
    text-transform:none;
    color:red;
    padding-top:5px;
    margin-left:10px;
}
    .imgshow img{
    max-width:600px;
    max-height:200px;
    }
    .erro {
        color:red;
    }
    #dm {
        height:30px;
    }
    #skyFileManger {
    width: 960px;
    margin: 0px auto;
    min-height: 300px;
    border: 1px solid #E4E4E4;
    padding: 3px;
}

#skFolder {
    width: 200px;
    float: left;
    height: 400px;
    overflow: auto;
}

#skFolderContent {
    width: 750px;
    float: left;
    background: whiteSmoke;
    height: 500px;
    overflow: auto;
    padding: 5px;
}

.skfile {
    width: 100px;
    height: 140px;
    border: 2px solid #ccc;
    padding: 5px;
    background: #FFF;
    float: left;
    margin: 10px;
    cursor: pointer;
}

    .skfile:hover {
        border: 2px solid #ddeff8;
        background: #f2f9fc;
    }

.skfilename {
    padding: 2px;
    text-align: center;
    margin-top: 10px;
}

.skselected {
    background: #ffdd88;
    border: 2px solid #ffbb00;
}

    .skselected:hover {
        background: #ffdd88;
        border: 2px solid #ffbb00;
    }

.skselected-folder {
    color: #000;
    font-weight: bold;
}

.skupload {
    padding-top: 5px;
}

.skselected-folder:hover {
    color: #000 !important;
}

.skfileicon-image {
    max-width: 90px;
    max-height: 100px;
}

.skfileicon {
    text-align: center;
    min-width: 90px;
    min-height: 60px;
}

#editFile {
    width: 300px;
    background: #3F3F49;
    padding: 10px 0px;
}

    #editFile label {
        font-weight: bold;
        color: White;
        padding-bottom: -20px;
        padding-left: 15px;
    }

    #editFile input {
        width: 100px;
        height: 35px;
        padding-right: 10px;
    }

.edFileName {
    color: White;
    margin: 10px 10px 0px 10px;
    display: block;
}

#editFile input.edNewFileName {
    width: auto;
    height: 5px;
    padding-right: 10px;
    margin-top: 10px;
    margin-left: 10px;
}

#editFile input#edSave {
    margin-left: 10px;
    margin-top: 5px;
}
  
</style>
<div class="container" style="padding:10px;">
    @using (Html.BeginForm()) { 
        <fieldset>
                 <legend >Chỉnh sửa công ty: <span style="color:#000">@Model.CompanyName</span></legend>
            </fieldset>
            
                 <div class="form-group">

            <label for="txttitle">Tên công ty (*)</label>

           @Html.TextBoxFor(m => m.CompanyName, new {@class="form-control",id="txttitle" })
          @Html.HiddenFor(m=>m.CompanyID)
                     @Html.HiddenFor(m=>m.LangID)
          </div>
 
        <div class="form-group">
            <label for="txtshortcontent">Logo</label>
            @Html.TextBoxFor(m => m.Logo, new {@readonly="readonly" }) <img id="imgshow" src="@Url.Content("~/Content/images/CompanyLogo/"+Model.Logo)" />
            <input type="button" id="chooseLogo" value="Chọn hình"/>
          </div>
          <div class="form-group">

            <label for="txttitle">Điện thoại (*)</label>

           @Html.TextBoxFor(m => m.Phone, new {@class="form-control" })

          </div>
         <div class="form-group">

            <label for="txttitle">Email (*)</label>

           @Html.TextBoxFor(m => m.Email, new {@class="form-control" })

          </div>
        <div class="form-group">

            <label for="txttitle">Fax (*)</label>

           @Html.TextBoxFor(m => m.Fax, new {@class="form-control" })

          </div>
         <div class="form-group">

            <label for="txttitle">Website (*)</label>

           @Html.TextBoxFor(m => m.Website, new {@class="form-control" })

          </div>
        <div class="form-group">

            <label for="txttitle">Address (*)</label>

           @Html.TextBoxFor(m => m.Address, new {@class="form-control" })

          </div>
         <div class="form-group">

            <label for="txttitle">Bật tắt (*)</label>

           @Html.CheckBoxFor(m => m.Enable)

          </div>
          <button type="submit" class="btn btn-success">Lưu thay đổi</button>
    }

</div>